<?php

namespace Admin\Controller;

use \Admin\Controller\AdminController;

/*
 * 接口管理类
 */

class EvalController extends AdminController {

    /**
     * 分店列表
     */
    public function index() {
        $where = array();
        //日期选择
        $select_date = I("select_date");
        if(!empty($select_date)){
            $where['te.addtime'] = array('like',$select_date.'%');
            $this->assign("select_date",$select_date);
        }
        //老师姓名
        $name = I("name");
        if(!empty($name)){
            $where['t.name'] = array('like',$name.'%');
            $this->assign("name",$name);
        }
        
        $list =  M()->table("ot_teacher_eval te")->field("te.*,t.name,s.shopname")
                    ->join("ot_teacher as t ON t.tid=te.tid")
                    ->join("ot_shop as s ON s.sid = te.sid")
                    ->where($where)
                    ->order("te.id desc")
                    ->select();
        
        $this->assign('_list',$list);
        $this->meta_title = '评分列表';
        $this->display();
    }

    /**
     * 添加分店
     */
    public function add() {
        if(IS_POST) {
            $data['shopname'] = I('shopname');
            $res              = M("Shop")->add($data);
            if($res) {
                $this->success('添加成功',U('index'));
            }
            else {
                $this->error('添加失败',U('add'));
            }
        }
        else {
            $this->meta_title = '添加分店';
            $this->display();
        }
    }

    /**
     * 编辑分店
     */
    public function edit() {
        if(IS_POST) {
            $data['sid']      = I("sid",0,'intval');
            $data['shopname'] = I('shopname');
            $res              = M("Shop")->save($data);
            if($res) {
                $this->success('编辑成功',U('index'));
            }
            else {
                $this->error('编辑失败');
            }
        }
        else {
            $sid              = I("sid");
            $data             = M("Shop")->where(array('sid' => $sid))->find();
            $this->meta_title = '编辑分店';
            $this->assign('data',$data);
            $this->display("add");
        }
    }

    /**
     * 删除分店
     */
    public function del() {
        $sids = I('sid');
        $res  = M("Shop")->where(array('sid' => array('in',explode(',',$sids))))->delete();
        if($res) {
            $this->success('删除成功',U('index'));
        }
        else {
            $this->error('删除失败');
        }
    }
    
    /**
     * 评价是否题答案
     */
    public function show() {
        $eid = I('eid');
        $teacherList = M()->table("ot_teacher_eval_is as tei")->field("tei.*,q.title")
                        ->join("ot_question as q ON q.qid = tei.qid")
                        ->where(array('tei.eid'=>$eid))
                        ->select();
        $this->assign('teacherList',$teacherList);
        $this->display();
    }

}
